from flask import Blueprint, request, jsonify, send_from_directory
import os

video_bp = Blueprint('video', __name__)

@video_bp.route('/ai/video/generate', methods=['POST'])
def generate_video():
    if 'image' not in request.files or 'text' not in request.form:
        return jsonify({'error': 'Image and text are required!'}), 400

    image = request.files['image']
    text = request.form['text']

    # Save the image to a temporary location
    image_path = os.path.join('temp', image.filename)
    image.save(image_path)

    # Here you would add your logic to generate the video using the image and text
    # For demonstration purposes, we'll just return a dummy video URL
    video_url = 'http://127.0.0.1:5000/static/video.mp4'

    return jsonify({'videoUrl': video_url})

@video_bp.route('/static/<path:filename>')
def serve_static(filename):
    return send_from_directory('static', filename)